﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.Globalization;
    using System.Xml;

    public class ObjectPathStaticMethod : ObjectPath
    {
        private string m_methodName;
        private object[] m_parameters;
        private ChunkStringBuilder m_sb;
        private SerializationContext m_serializationContext;
        private string m_typeId;

        public ObjectPathStaticMethod(ClientRuntimeContext context, string typeId, string methodName, object[] parameters) : base(context, null, true)
        {
            this.m_typeId = typeId;
            this.m_methodName = methodName;
            this.m_parameters = parameters;
            this.m_serializationContext = new SerializationContext();
            this.m_sb = new ChunkStringBuilder();
            XmlWriter writer = this.m_sb.CreateXmlWriter();
            this.WriteToXmlPrivate(writer, this.m_serializationContext);
            writer.Close();
            this.m_parameters = null;
        }

        internal override void Invalidate()
        {
            this.m_parameters = null;
            this.m_sb = null;
            this.m_serializationContext = null;
            base.IsValid = false;
        }

        internal override void WriteToXml(XmlWriter writer, SerializationContext serializationContext)
        {
            this.m_sb.WriteContentAsRawXml(writer);
            serializationContext.AddObjectPathsFrom(this.m_serializationContext);
        }

        private void WriteToXmlPrivate(XmlWriter writer, SerializationContext serializationContext)
        {
            writer.WriteStartElement("StaticMethod");
            writer.WriteAttributeString("Id", base.Id.ToString(CultureInfo.InvariantCulture));
            writer.WriteAttributeString("Name", this.m_methodName);
            writer.WriteAttributeString("TypeId", this.m_typeId);
            if ((this.m_parameters != null) && (this.m_parameters.Length > 0))
            {
                writer.WriteStartElement("Parameters");
                foreach (object obj2 in this.m_parameters)
                {
                    writer.WriteStartElement("Parameter");
                    DataConvert.WriteValueToXmlElement(writer, obj2, serializationContext);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
        }
    }
}

